package sz.com.postoffice.jxyzwgcase.controller;

import com.sun.istack.NotNull;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sz.com.postoffice.jxyzwgcase.core.TableDataInfo;
import sz.com.postoffice.jxyzwgcase.pojo.MonthPlan;
import sz.com.postoffice.jxyzwgcase.service.MonthPlanService;
import sz.com.postoffice.jxyzwgcase.service.PersonnelSectionService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MonthPlanController
 * @Deacription
 * @Author jmx
 * @Date 2020/11/12 19:52
 * @Version 1.0
 **/
@Api(value = "月计划", tags = "{月计划API}")
@RestController
@Slf4j
@RequestMapping(value = "/monthPlan")
public class MonthPlanController {
    @Resource
    private MonthPlanService monthPlanService;
    @Resource
    private PersonnelSectionService personnelSectionService;

    @ApiOperation(value = "新增月计划信息", notes = "新增月计划信息")
    @RequestMapping(value = "/plans", method = RequestMethod.POST)
    public boolean insert(@RequestBody MonthPlan monthPlan) {
        System.out.println("开始新增...");
        return monthPlanService.insert(monthPlan);
    }

    @ApiOperation(value = "批量处理月计划信息", notes = "批量处理月计划信息")
    @RequestMapping(value = "/plans/batch", method = RequestMethod.POST)
    public void batchInsert(@RequestBody List<MonthPlan> monthPlanList) {
        System.out.println("开始处理...");
        monthPlanService.batchUpdate(monthPlanList);
    }

    @ApiOperation(value = "更新月计划信息", notes = "更新月计划信息")
    @RequestMapping(value = "/plans", method = RequestMethod.PUT)
    public boolean update(@RequestBody MonthPlan monthPlan) {
        System.out.println("开始更新...");
        return monthPlanService.update(monthPlan);
    }

    @ApiOperation(value = "删除月计划信息", notes = "删除月计划信息")
    @RequestMapping(value = "/plans/{pid}", method = RequestMethod.DELETE)
    public boolean delete(@PathVariable("pid") @NotNull @ApiParam(name="月计划id",value="path传入",required=true) Integer pid)  {
        System.out.println("开始删除...");
        return monthPlanService.deleteByPrimaryKey(pid);
    }

    @ApiOperation(value = "根据部门日期查询月计划信息列表", notes = "根据部门日期查询月计划信息列表")
    @RequestMapping(value = "/plans", method = RequestMethod.GET)
    public TableDataInfo findByMonthPlan(MonthPlan monthPlan) {
        System.out.println("开始查询...");
        return monthPlanService.findByDeptAndMonth(monthPlan.getDeptCode(), monthPlan.getPlanMonth());
    }
}
